/*
 * @Author: Starfish_DL
 * @Date: 2020-11-08 13:48:31
 * @LastEditors: Starfish_DL
 * @LastEditTime: 2020-11-08 22:45:45
 * @CurrentVersion: 1.0
 * @Description: 
 */

public class Communication implements Runnable {
    private int i = 1;

    @Override
    public void run() {
        while (true) {
            synchronized (this) {
                this.notify();
                if (i <= 100) {
                    System.out.println(Thread.currentThread().getName() + ":" + i++);
                } else {
                    break;
                }
                try {
                    this.wait();
                } catch (InterruptedException e) {
                    // DONE: handle exception
                }
            }
        }
    }
}

/**
 * InnerCommunication
 */
class InnerCommunication {

    public static void main(String[] args) {
        Communication com = new Communication();
        Thread t1 = new Thread(com, "Thread1");
        Thread t2 = new Thread(com, "Thread2");
        t1.start();
        t2.start();
    }
}
